package Control;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import Model.XGerarTabelas;
import View.Facade;

public class ControlServlet extends HttpServlet{
	
	Facade facade = Facade.getInstance();
	
	protected void doGet(HttpServletRequest request, 
			HttpServletResponse response)
	throws ServletException, IOException {
		this.answer(request, response);
	}
	
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) 
	throws ServletException, IOException{
		this.answer(request, response);
	}	
	
	protected void answer(HttpServletRequest request, 
			HttpServletResponse response)
	throws ServletException, IOException {
		
		String retorno = "";
		
		try {
			if (request.getRequestURI().endsWith("login")){
				retorno = fazLogin(request , response);
			}
			if (request.getRequestURI().endsWith("add_ua")){
				retorno = addUA(request , response);
			} 
		} catch (Exception e) {
			e.printStackTrace();
		}
		
        request.getRequestDispatcher(retorno).
        			forward(request, response);
	}
	
	public String fazLogin(HttpServletRequest request,
			HttpServletResponse response)
	throws ServletException, IOException {
		String login = request.getParameter("usuarioTextField");
        String senha = request.getParameter("senhaTextField");
        if (login.equals("simfi") && senha.equals("simfi123")){
        	return "TelaApresentacao.jsp";
        }
		return "login_erro.jsp";
	}
	
	public String addUA(HttpServletRequest request,
			HttpServletResponse response)
	throws ServletException, IOException {
		//facade.cadastrarDepartamento(codigoDepartamento, nomeDepartamento, nomeChefe, siglaDepartamento, nomeSubChefe, emailChefe, emailSubChefe, senhaUsuario, telefoneChefe, telefoneSubchefe, faxChefe, faxSubChefe, celularChefe, celularSubChefe)
		return "";		
	}
	
}
